<template>
  <el-dialog append-to-body title="批量开票导入" :show-close="false" :close-on-click-modal="false"
             :close-on-press-escape="false" :destroy-on-close="true" :visible.sync="invoiceVisible" :width="'640px'"
  >

    <div style="display: flex;align-items: center">
      <span style="margin-right: 20px">上传文件</span>
      <el-upload
        class="upload-demo"
        :action="uploadUrl"
        multiple
        :limit="1"
        :headers="header"
        :on-success="uploadSuccess"
        accept="application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        :show-file-list="false">
        <el-button size="small" >上传文件</el-button>
      </el-upload>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="closeModal()">取消</el-button>
      <el-button type="primary" @click="closeModal()">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getToken } from '@/utils/Token'

export default {
  name: 'invoiceImport',
  data() {
    return {
      uploadUrl: `${process.env.VUE_APP_BASE_API}/cloudApi/order/importOrderOpenInvoice`,
      header:{ContentType:"multipart/form-data", Authorization: getToken()},
    }
  },
  props:{
  invoiceVisible: {
    type: Boolean,
    default: false
  }
  },
  methods: {
    closeModal() {
      this.$emit('close')
    },
    uploadSuccess(response, file, fileList){
      console.log(response)
      if(response.code == 200){
        this.$message({
          message: '操作成功',
          type: 'success'
        });
        this.$emit('submit')
      }else{
        this.$message({
          message: response.msg,
          type: 'success'
        });
      }
    }
  }
}
</script>

<style scoped>

</style>
